/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.gob.foncodes.ssa.bs.common.util;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 *
 */
public class FuncionesStaticas implements Serializable  {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = -3675243726536427783L;
        
    public static void copyPropertiesObject(Object a, Object b) {
            try {
                if (a == null || b == null)
                        return;
                Field camposdea[] = b.getClass().getDeclaredFields();
                for (int i = 0; i < camposdea.length; i++) {
                    String camponame = camposdea[i].getName();
                    String sgetMetod = "get"
                                    + Character.toUpperCase(camponame.charAt(0))
                                    + camponame.substring(1);
                    String ssetMetod = "set"
                                    + Character.toUpperCase(camponame.charAt(0))
                                    + camponame.substring(1);
                    Class<?>[] types = new Class[] {};
                    try {
                            Method method = b.getClass().getMethod(sgetMetod, types);
                            Object valuecampoa = method.invoke(b, new Object[0]);
                            Class<?> types2 = camposdea[i].getType();
                            Method method2 = a.getClass().getMethod(ssetMetod, types2);
                            method2.invoke(a, valuecampoa);
                    } catch (NoSuchMethodException exception) {
                            // System.out.println("Error NoSuchMethodException: " +
                            // exception.getMessage());
                    }
                }
            } catch (Exception e) {
                    System.out.println("Error exception: " + e.getMessage());
                    e.printStackTrace();
            }
	}
        
}
